import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xvideos/hj_page/mine_business/collec_history_buy/col_his_buy_page.dart';
import 'package:xvideos/hj_page/mine_business/collec_history_buy/col_his_buy_sub_page.dart';
import 'package:xvideos/tools_base/widget/keep_alive_widget.dart';

abstract class BaseColHisBuyMainController extends GetxController with GetSingleTickerProviderStateMixin {
  final sorts = ['影视', '短片', '漫画', '动漫', '小说', '帖子', '合集'];
  bool isEdit = false;
  late final TabController controller = TabController(length: sorts.length, vsync: this);
  final PageType type;

  BaseColHisBuyMainController(this.type);

  List<Widget> instanceChildren();

  onDeteleAction() => UnimplementedError();
}

class HistoryController extends BaseColHisBuyMainController {
  HistoryController(super.type);

  @override
  List<String> get sorts => ['影视', "抖音", '帖子', "漫画", "动漫", "图集", "小说", "游戏"];

  @override
  List<Widget> instanceChildren() {
    return [
      ColHisBuySubPage(LoadDataType.video, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.short, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.post, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.comics, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.cartoon, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.pictures, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.novel, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.game, pageType: type, isEdit: isEdit).keepAlive,
    ];
  }

  //删除操作
  @override
  onDeteleAction() {
    isEdit = !isEdit;
    update();
  }
}

//我的收藏
class CollectionController extends BaseColHisBuyMainController {
  CollectionController(super.type);

  @override
  List<String> get sorts => ['影视', "抖音", '帖子', "漫画", "动漫", "图集", "小说", '游戏'];

  @override
  List<Widget> instanceChildren() {
    return [
      ColHisBuySubPage(LoadDataType.video, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.short, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.post, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.comics, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.cartoon, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.pictures, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.novel, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.game, pageType: type, isEdit: isEdit).keepAlive,
    ];
  }

  //删除操作
  @override
  onDeteleAction() {
    isEdit = !isEdit;
    update();
  }
}

class BuyController extends BaseColHisBuyMainController {
  BuyController(super.type);

  @override
  List<String> get sorts => ['影视', "抖音", '帖子', "漫画", "动漫", "图集", "小说", '游戏'];

  @override
  List<Widget> instanceChildren() {
    return [
      ColHisBuySubPage(LoadDataType.video, pageType: type).keepAlive,
      ColHisBuySubPage(LoadDataType.short, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.post, pageType: type).keepAlive,
      ColHisBuySubPage(LoadDataType.comics, pageType: type).keepAlive,
      ColHisBuySubPage(LoadDataType.cartoon, pageType: type).keepAlive,
      ColHisBuySubPage(LoadDataType.pictures, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.novel, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.game, pageType: type, isEdit: isEdit).keepAlive,
    ];
  }
}

class LikeController extends BaseColHisBuyMainController {
  LikeController(super.type);

  @override
  List<String> get sorts => ['影视', "抖音", '帖子', "漫画", "动漫", "图集", '游戏'];

  @override
  List<Widget> instanceChildren() {
    return [
      ColHisBuySubPage(LoadDataType.video, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.short, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.post, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.comics, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.cartoon, pageType: type, isEdit: isEdit).keepAlive,
      ColHisBuySubPage(LoadDataType.pictures, pageType: type, isEdit: isEdit).keepAlive,
      // ColHisBuySubPage(LoadDataType.novel, pageType: type).keepAlive,
      ColHisBuySubPage(LoadDataType.game, pageType: type, isEdit: isEdit).keepAlive,
    ];
  }

  //删除操作
  @override
  onDeteleAction() {
    isEdit = !isEdit;
    update();
  }
}

BaseColHisBuyMainController instanceController(PageType type) {
  switch (type) {
    case PageType.buy:
      return BuyController(type);
    case PageType.collect:
      return CollectionController(type);
    case PageType.history:
      return HistoryController(type);
    case PageType.like:
      return LikeController(type);
    default:
      throw '$type 没有对应的类型';
  }
}
